from functools import wraps
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from rest_framework import status


def is_root_login(view):
    @wraps(view)
    def wrapper(request, *args, **kwargs):
        if not (request.user.is_authenticated and request.user.is_staff):
            return JsonResponse({'message': '没有权限,请联系管理员'}, status=status.HTTP_400_BAD_REQUEST)
        response = view(request, *args, **kwargs)

        return response
    return wrapper